package com.study.jdbc.junit;

import java.util.Date;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.study.jdbc.domain.Customer;
import com.study.jdbc.factory.BeanFactory;
import com.study.jdbc.service.CustomerService;

public class CustomerServiceTest {
	
	private CustomerService customerService = null ;
	
	@Before
	public void setUp() {
		customerService = BeanFactory.getInstance().getCustomerServiceImpl() ;
	}
	
	@Test
	public void testFindCustomerById() {
		String id = "f647c2b7-eb9a-455c-9992-aed938b7929d" ;
		Customer customer = customerService.findCustomerById(id) ;
		System.out.println(customer);
	}

	@Test
	public void testFindAllCustomers() {
		List<Customer> customers = customerService.findAllCustomers() ;
		for (Customer customer : customers) {
			System.out.println(customer);
		}
	}

	@Test
	public void testSaveCustomer() {
		Customer customer = new Customer() ;
		customer.setName("王五") ;
		customer.setGender("女") ;
		customer.setBirthday(new java.sql.Date(new Date().getTime())) ;
		customer.setCellphone("18810291234") ;
		customer.setEmail("123@321.com") ;
		customer.setPreference("游泳！") ;
		customer.setType("普通客户") ;
		customer.setDescription("好！") ;
		customerService.saveCustomer(customer) ;
	}

	@Test
	public void testUpdateCustomer() {
		Customer customer = new Customer() ;
		String id = "33084f0c-1c78-489d-b3c1-eea5ad632af7" ;
		customer.setId(id) ;
		customer.setName("王流") ;
		customer.setGender("男") ;
		customer.setBirthday(new java.sql.Date(new Date().getTime())) ;
		customer.setCellphone("18810290000") ;
		customer.setEmail("123@321.com") ;
		customer.setPreference("游泳！") ;
		customer.setType("普通客户") ;
		customer.setDescription("不好！") ;
		customerService.updateCustomer(customer) ;
	}

	@Test
	public void testDeleteCustomerById() {
		String id = "b4af2198-05d0-48c9-9b50-d58c2d3bda84" ;
		customerService.deleteCustomerById(id) ;
	}

}
